/***
 * 此util主要提供一些常用的日期工具和日期处理
 */
class DateUtil{
  private nowDate:Date = new Date();
  //年
  year:number = this.nowDate.getFullYear();
  //月
  month:number = this.nowDate.getMonth();
  //日
  date:number = this.nowDate.getDate();
  //周几
  weekDay:number = this.nowDate.getDay();

  completeWeekDate(){
    let weekDates = [];

    // 获取本周的第一天（周日）
    let  firstDay = new Date();
    firstDay.setDate(firstDay.getDate() - this.nowDate.getDay());

    // 生成一周的日期列表-
    for (let  i = 1; i <= 7; i++) {
      let date = new Date(firstDay);
      date.setDate(date.getDate() + i);
      let dateString = (date.getMonth() + 1).toString() + '/' + date.getDate().toString();
      weekDates.push(dateString);
    }
    return weekDates;
  }

  //返回X月
  monthString(){
    return (this.month + 1).toString() + "\n" + "月";
  }

  //返回xxxx-xx-xx日期格式
  formatDate():string{
    // return "2024-2-21";
    return `${this.year}-${this.month}-${this.date}`;
  }

  //根据日期判断是第几周
  getWeekNumber(inputDate:string):string{
    // 获取输入日期
    let firstDayOfWeek = new Date(inputDate);
    // 获取当前日期
    let firstDayOfCurrentWeek = new Date();
    // 计算当前日期所在周相对于输入日期所在周的周数差
    var timeDiff = firstDayOfCurrentWeek.getDate() - firstDayOfWeek.getDate();
    var weekDiff = Math.floor(timeDiff / 7) + 1;

    return weekDiff.toString();
  }

  //将周字符串转为数字
  parseWeekString_Number(weekStr:string):number{
    switch (weekStr){
      case '周一':return 1;
      case '周二':return 2;
      case '周三':return 3;
      case '周四':return 4;
      case '周五':return 5;
      case '周六':return 6;
      case '周日':return 7;
      default :return;
    }
  }

  //将节数字符串转为数字时间
  parseTimeString_Number(timeStr:string):string{
    switch (timeStr) {
      case '第1-2节':return '08:00 - 09:40';
      case '第3-4节':return '10:00 - 11:40';
      case '第5-6节':return '14:30 - 16:10';
      case '第7-8节':return '16:30 - 18:10';
      case '第9-10节':return '19:30 - 21:10';
    }
  }

}

let dateUtil = new DateUtil();
export default dateUtil as DateUtil;